package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入要归还图书的名称");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();


        int currentUsedSize = bookList.getUsedSize();
        for (int i = 0; i < currentUsedSize; i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                if(book.isBorrowed()){
                    book.setBorrowed(false);
                    System.out.println("归还成功");
                }else{
                    System.out.println("你并没有借阅此书，不需要归还图书");
                }
                return;
            }
        }
        System.out.println("没有找到此图书");
    }
}
